const AssetsProxyService = require("./../service/AssetsProxyService");

const AssetsProxyController = {
  async getFile(req, res) {
    const data = req.body;

    if (!data.url) {
      return res.status(400).send({
        code: 400,
        message: "请传入url参数",
        data: null,
      });
    }

    try {
      const imageData = await AssetsProxyService.getFile(data);
      res.header("Content-Type", "image/jpeg");
      res.send(imageData);
    } catch (err) {
      res.status(err.status).send({
        code: err.status,
        message: err.message,
        data: err.data || null,
      });
    }
  },
};

module.exports = AssetsProxyController;
